<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
        <style>
            .d {
                width: 100px;
                height: 100px;
                border: 1px solid gold;
            }
        </style>
    </head>
    <body>
        <div id="app">
            <div class="d" v-pos:[position]="h"></div>
        </div>
        <script src="../vue.js"></script>
        <script>
            new Vue({
                el: '#app',
                data() {
                    return {
                        h: 200,
                        position: {
                            t: 'top',
                            l: 'left',
                        },
                    };
                },
                directives: {
                    pos: {
                        // bind: 只会执行一次
                        bind(el, binding, vNode) {
                            el.style.position = 'fixed';
                            // console.log(binding);
                            // let p = binding.arg === 'top' ? 'top' : 'left';
                            let p = binding.arg;
                            // console.log( el.style);
                            el.style[p.l] = binding.value + 'px';
                            el.style[p.t] = binding.value + 'px';
                        },
                    },
                },
            });
        </script>
    </body>
</html>
